package cn.edu.bnu.land.domain;

// Generated 2015-1-26 20:20:05 by Hibernate Tools 3.4.0.CR1

import java.awt.Point;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import cn.edu.bnu.common.dao.impl.BaseDaoHibernate4;


/**
 * Home object for domain model class Dcgj.
 * @see cn.edu.bnu.land.domain.Dcgj
 * @author Hibernate Tools
 */

public class DcgjDao extends BaseDaoHibernate4<DcgjId>{

	public List<DcgjId> getUsers(){
		return findAll(DcgjId.class);
	//	return find("select * from users");
	}
  //获取查询轨迹
  public List<HashMap<String, Object>> handler(Date start,Date end){
	  
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//	   String startDateString = formatter.format(start);
//	   String endtDateString = formatter.format(end);
	  
	  String hql = " select new map(id.gjid as guijihao,id.rwid as renwuhao,"
	  		+ "id.sj as time) from Dcgj where id.sj between ? and ?"; 
	  Session session=getSession();
        Query query = session.createQuery(hql);
        query.setDate(0, start);
        query.setDate(1,end);
        List<HashMap<String, Object>> list = query.list();  
        for (HashMap<String, Object> hashMap : list) {
        	Date currentTime=(Date) hashMap.get("time");
        	   //SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        	   String dateString = formatter.format(currentTime);
        	   hashMap.put("time", dateString);
        	   }
	  
	  return list;
  }
  //获取查询轨迹坐标
  public ArrayList<List<Float>>  getGuiJiZuoBiao(String guiJiHao){
	  
	
	  String hql = " select dc.id.gjzb from Dcgj as dc where dc.id.gjid='"+guiJiHao+"'"; 
	  Session session=getSession();
        Query query = session.createQuery(hql);
  
        List<String> list = query.list();
        String[] stringList = null;
        ArrayList<List<Float>> resultList=new ArrayList<List<Float>>();
        for (String itemString : list) {
        	itemString=itemString.replace(" ", "");
        	stringList=itemString.split(";");
        	for (String item : stringList){
        		 List<Float> set=new ArrayList<Float>();
        		 String[] dd=item.split(",");
        		 for(String i:dd){
        			 set.add(Float.parseFloat(i));
        		 }
        		 resultList.add(set);
        	}
        	list.clear();
        	break;
        	
        }
	  
	  return resultList;
  }
}
